package com.apes.fn.scm.retailOrder.service.tc.tcOutbox;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.util.DateUtil;
import com.apes.hr.base.model.EmployeeFamily;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.voucher.model.VoucherItem;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 功能：平台外接送车
 *
 * @author linwz
 * @create 2021-03-15 10:00
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TcOutPickCar.CONST_TABLE_NAME)
public class TcOutPickCar extends Model {
	public static final String CONST_TABLE_NAME = "tc_out_pick_car";

	@Id
	@Column(name="id")
	@ApesGenerator(code = CONST_TABLE_NAME, name = "平台外接送车",prefix = "OP")
	private String id;

	@Comment("部门")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "dept_id", referencedColumnName = "id")
	private Dept dept; //部门

	@Comment("人员")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "visitor_id", referencedColumnName = "id")
	private PartyRole visitor;

	@Column(name = "remark", length = 128)
	@Comment("备注")
	private String remark;

	@Column(name = "state", length = 10)
	@Comment("状态")
	private String state; //状态

	@JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "approve_Date")
	@Comment("审核时间")
	private Date approveDate;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "approve_Uid", referencedColumnName = "id")
	@Comment("审核人")
	private PartyRole approveUid;

	@OneToMany(mappedBy = "tcOutPickCar", cascade = CascadeType.ALL, orphanRemoval = true)
	private Set<TcOutPickCarItem> tcOutPickCarItems = new HashSet(); //平台外接送车明细


	public Set<TcOutPickCarItem> getTcOutPickCarItems() {
		if (tcOutPickCarItems == null) return null;
		for (TcOutPickCarItem tcOutPickCarItem : tcOutPickCarItems) {
			tcOutPickCarItem.setTcOutPickCar(this);
		}
		return tcOutPickCarItems;
	}
	public void setTcOutPickCarItems(Set<TcOutPickCarItem> tcOutPickCarItems) {
		if (tcOutPickCarItems == null) tcOutPickCarItems = new HashSet<>();
		this.tcOutPickCarItems.clear();
		this.tcOutPickCarItems.addAll(tcOutPickCarItems);
	}
}
